// pages/personage.js
var app = getApp();
var getSign = require('../../utils/getSign/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    baseUrl: '',
    Logo:'',
    Nick_Name:'',
    bannerData:[],
    phone:'',
    wx:''
  },
  //拨打电话
  bodadianhua: function () {
    wx.makePhoneCall({
      phoneNumber: this.data.phone
    })
  },
  //添加微信
  tianjiaweixin: function () {
    wx.setClipboardData({
      data: this.data.wx,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            console.log('复制成功')
            console.log(res.data) // data
            wx.showToast({
              title: '微信号已复制',
              icon: 'success',
              duration: 2000
            })
            setTimeout(() => {
              wx.showToast({
                title: '请添加好友',
                icon: 'success',
                duration: 2000
              })
            }, 2000)
          }
        })
      }
    })
  },

  goOutweb: function (event){
    var url = event.currentTarget.dataset['url'].replace('?', '$')
    url = url.replace(/=/g, '%')
    url = url.replace(/&/g, '@')
    wx.navigateTo({
      url: '/pages/outweb/outweb?url=' + url,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      baseUrl: app.baseUrl
    })
    // var userinfos = wx.getStorageSync('userInfo')
    // var phones = wx.getStorageSync('phone')
    // var wxs = wx.getStorageSync('wx')
    // this.setData({
    //   userinfo: userinfos,
    //   phone: phones,
    //   wx: wxs
    // })
    this.requestPost('014')
  },


  //发送请求
  requestPost: function (apitype) {
    var memberInfo = wx.getStorageSync('memberInfo')
    var postArgs = {
      'Api_Type': apitype,
      'Member_Id': memberInfo.MemberId,
      'Member_Token': memberInfo.MemberToken
    }
    //获取
    getSign.request('https://wx-app-api.sjune.cn/yuren/API.ashx', 'POST', postArgs, '').then(
      (res) => {
        console.log(res, '个人中心')
        if (res.Status == 2) {
          wx.clearStorage({
            success: () => {
              wx.switchTab({
                url: '/pages/index/index',
              })
            }
          })
        } else if (res.Status == 0) {
          this.setData({
            Logo: res.Data.Logo,
            Nick_Name: res.Data.Nick_Name,
            bannerData: res.Data.bannerData,
            phone: res.Data.phone,
            wx: res.Data.wx
          })
        }
        
      },
      (err) => {
        console.log(err.Message, '成功列表失败')
      }
    )
  },

  collection:function()
  {
    wx.switchTab({
      url: '/pages/collection/collection',
    })
  },
  Order:function(e)
  {
    if (e.currentTarget.id==1)
    {
      wx.navigateTo({
        url: '../serve/serve?id=1',
      })
    } else if (e.currentTarget.id==2){
      wx.navigateTo({
        url: '../serve/serve?id=2',
      })
    } else if (e.currentTarget.id==3){
      wx.navigateTo({
        url: '../serve/serve?id=3',
      })
    }
    
  },
  personal:function()
  {
    wx.navigateTo({
      url: '/pages/personeditor/personeditor',
    })
  },
  Ticketlist:function()
  {
    wx.navigateTo({
      url: '../ticketlist/ticketlist',
    })
  },
  personal:function()
  {
    wx.navigateTo({
      url: '../personeditor/personeditor',
    })
  },
  Total:function(){
    wx.navigateTo({
      url: '../serve/serve?id=0',
    })
  },
  aboutdetail:function()
  {
    wx.navigateTo({
      url: '/pages/about/about',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.requestPost('014')
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})